﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using GKBErps.Models;
using GKBErps.Model;
using GKBErps.BLL.sys;
using Microsoft.AspNetCore.Http;
using GKBErps.Common;
using Newtonsoft.Json;
using GKBErps.Common.ConfigHelper;
using GKBErps.DAL.sys;
using GKBErps.Model.dto;

namespace GKBErps.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;
        private sys_userBLL userBLL = new sys_userBLL();
        private sys_menuBLL sys_MenuBLL = new sys_menuBLL();

        public object CodingUtils { get; private set; }

        public HomeController(ILogger<HomeController> logger)
        {
            _logger = logger;
        }

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Main()
        {
            return View();
        }

        /// <summary>
        /// 获取当前用户信息
        /// </summary>
        /// <returns></returns>
        public ActionResult GetUserInfo() {
            string userid = HttpContext.Session.GetInt32(SessionKey.USERID.ToString()).ToString();
            sys_user userModel = userBLL.GetById(userid);
            List<menuDTO> sys_Menus = sys_MenuBLL.GetListByRoleids(null);
            object jsonResult = new { code = ErrorCode.A0000.ToString(), data = new {
                userInfo = userModel,
                menuList = sys_Menus
            } };
            var jsonstr = JsonConvert.SerializeObject(jsonResult);
            return Content(jsonstr);

        }

        public IActionResult Privacy()
        {
             return View("login");
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
